<template>
  <view>
    <uni-search-bar @input="input"></uni-search-bar>
    <my-hot-item v-for="(v, i) in list" :key="i" :image="v.image" :title="v.title" :count="v.count">
      <view>
        {{v.address}}
      </view>
      <view>
        {{v.type}}
      </view>
    </my-hot-item>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        list: [],
        value: '',
        timer: null
      };
    },
    onLoad() {
      this.fetchList()
    },
    methods: {
      input(value) {
        clearTimeout(this.timer)

        this.timer = setTimeout(() => {
          this.value = value;
          this.fetchList()
        }, 400)

      },
      fetchList() {
        uni.request({
          url: 'http://localhost:3000/list',
          data: {
            // 模糊搜索
            q: this.value
          },
          success: (resp) => {
            console.log(resp.data)
            this.list = resp.data
          }
        })
      }
    },
  }
</script>

<style lang="scss">

</style>
